package online.lmds.sdmanage.main.message;

import online.lmds.sdmanage.main.device.entity.Device;
import online.lmds.sdmanage.main.device.entity.DeviceLog;
import online.lmds.sdmanage.main.message.entity.MqttLog;

/**
 * Created by Brighten Ma on 2017/5/1.
 */
public class MqttUtil {

    public static  String getControlDeviec(MqttLog mqttLog){
        if (mqttLog != null && mqttLog.getDeviceId() != null){
            return mqttLog.getDeviceId();
        } else {
            return null;
        }
    }


    public static int getStatus(MqttLog mqttLog){
        if (mqttLog == null){
            throw new RuntimeException("mqtt is null");
        }
        if (mqttLog.getData() != null) {
           return mqttLog.getDeviceStatus();
        }

        return Device.STATUS_UNKNOW;

    }


    public static Device getDevice(MqttLog mqttLog){
        Device device = new Device();
        device.setUid(mqttLog.getDeviceId());
        device.setStatus(mqttLog.getDeviceStatus());
        device.setInfo(mqttLog.getData().toString());
        return device;
    }



    public static DeviceLog getDeviceLog(MqttLog mqttLog){
        DeviceLog deviceLog = new DeviceLog();
        deviceLog.setUid(mqttLog.getDeviceId());
        deviceLog.setStatus(mqttLog.getCacheStatus());
        deviceLog.setInfo(mqttLog.getData().toString());
        return deviceLog;
    }
}
